*Table A.30: Meal and Snack treatment effects on food preferences using alternative inference procedures
cd ""

use master_data_adults_child_s13456_shared.dta, clear

drop meal_control snack_control
gen meal_control=1 if treatment==2
replace meal_control=0 if treatment==1
tab meal_control

gen snack_control=1 if treatment==3
replace snack_control=0 if treatment==1
tab snack_control

drop if type_id=="X" // **Dropping newborns born during the three years of study
drop if id=="3885553B" //**error in the id number and empty data
drop if id=="3885553G" //**error in the id number and empty data
replace treatment=2 if id=="38855553B" //**retrieving the correct treatment for this id
replace treatment=2 if id=="38855553G" //**retrieving the correct treatment for this id
drop if id=="101aa22c" //**this id does not exist

********************************************************************************
ge meal=(treatment==2)
replace meal=. if treatment==.

ge snack=(treatment==3)
replace snack=. if treatment==.

ge session1=(session==1)
replace session1=. if session==.

ge session3=(session==3)
replace session3=. if session==.

ge session4=(session==4)
replace session4=. if session==.

ge session5=(session==5)
replace session5=. if session==.

ge session6=(session==6)
replace session6=. if session==.

ge meal_session1=meal*session1
ge meal_session3=meal*session3
ge meal_session4=meal*session4
ge meal_session5=meal*session5
ge meal_session6=meal*session6

ge snack_session1=snack*session1
ge snack_session3=snack*session3
ge snack_session4=snack*session4
ge snack_session5=snack*session5
ge snack_session6=snack*session6

set more off

xtset id_nb session
***Panel A: Children******
*Results

set more off
foreach x in fp_fruit fp_veg fp_meat_fish_egg fp_processed fp_sweets fp_bread fp_cheese {
xtreg `x' session3 session4 session5 session6 meal_session3 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6 if child==1, cluster(hh_id) fe

*****Randomisation Inference****
randcmd ((meal_session3 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6) ///
xtreg `x' session3 session4 session5 session6 meal_session3 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6 if child==1, cluster(hh_id) fe),  ///
treatvars(meal_session3 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6) seed(123) reps(5000)
matrix b=e(RCoef)
local randt_m3=b[1,5]
local randt_m4=b[2,5]
local randt_m5=b[3,5]
local randt_m6=b[4,5]

local randt_s3=b[5,5]
local randt_s4=b[6,5]
local randt_s5=b[7,5]
local randt_s6=b[8,5]

xtreg `x' session3 session4 session5 session6 meal_session3 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6 if child==1, cluster(hh_id) fe

*Joint tests
*meal all
test meal_session3 meal_session4 meal_session5 meal_session6
local meal=r(p)

*snack all
test snack_session3 snack_session4 snack_session5 snack_session6
local snack=r(p)

*meal medium/long
test meal_session4 meal_session5 meal_session6 
local mlr=r(p)

*snack medium/long
test snack_session4 snack_session5 snack_session6 
local slr=r(p)

outreg2 using FoodPreferences_RI.xls, label ctitle(`x') dec(3) append excel ///
addstat(Meal joint, `meal', Snack joint, `snack', Meal long, `mlr', Snack long, `slr', ///
RI p-val MS3, `randt_m3', RI p-val MS4, `randt_m4', RI p-val MS5, `randt_m5', RI p-val MS6, `randt_m6', ///
RI p-val SS3, `randt_s3', RI p-val SS4, `randt_s4', RI p-val SS5, `randt_s5', RI p-val SS6, `randt_s6') ///
keep(session3 session4 session5 session6 meal_session3 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6) 
}


***Panel B: Adults******
*Results
set more off
foreach x in fp_fruit fp_veg fp_meat_fish_egg fp_processed fp_sweets fp_bread fp_cheese  {
xtreg `x' session3 session4 session5 session6 meal_session3 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6 if child==0, cluster(hh_id) fe

****Randomisation Inference****

randcmd ((meal_session3 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6) ///
xtreg `x' session3 session4 session5 session6 meal_session3 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6 if child==0, cluster(hh_id) fe),  ///
treatvars(meal_session3 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6) seed(123) reps(5000)
matrix b=e(RCoef)
local randt_m3=b[1,5]
local randt_m4=b[2,5]
local randt_m5=b[3,5]
local randt_m6=b[4,5]

local randt_s3=b[5,5]
local randt_s4=b[6,5]
local randt_s5=b[7,5]
local randt_s6=b[8,5]

xtreg `x' session3 session4 session5 session6 meal_session3 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6 if child==0, cluster(hh_id) fe

*Joint tests
*meal all
test meal_session3 meal_session4 meal_session5 meal_session6
local meal=r(p)

*snack all
test snack_session3 snack_session4 snack_session5 snack_session6
local snack=r(p)


*meal medium/long
test meal_session4 meal_session5 meal_session6 
local mlr=r(p)

*snack medium/long
test snack_session4 snack_session5 snack_session6 
local slr=r(p)

outreg2 using FoodPreferences_RI.xls, label ctitle(`x') dec(3) append excel ///
addstat(Meal joint, `meal', Snack joint, `snack', Meal long, `mlr', Snack long, `slr', ///
RI p-val MS3, `randt_m3', RI p-val MS4, `randt_m4', RI p-val MS5, `randt_m5', RI p-val MS6, `randt_m6', ///
RI p-val SS3, `randt_s3', RI p-val SS4, `randt_s4', RI p-val SS5, `randt_s5', RI p-val SS6, `randt_s6') ///
keep(session3 session4 session5 session6 meal_session3 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6) 

beep 
}



*Romano Wolf - p-values
*Meal Session 3
ge fp_mfe=fp_meat_fish_egg
keep child fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese hh_id meal_session3 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6 session3 session4 session5 session6 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6 id_nb
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese if child==1, cl(hh_id) method(xtreg) fe /// 
indepvar(meal_session3) controls(session3 session4 session5 session6 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6) reps(5000) seed(123)
beep 

*Meal Session 4
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese if child==1, cl(hh_id) method(xtreg) fe /// 
indepvar(meal_session4) controls(session3 session4 session5 session6 meal_session3 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6) reps(5000) seed(123)
beep

*Meal Session 5
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese if child==1, cl(hh_id) method(xtreg) fe /// 
indepvar(meal_session5) controls(session3 session4 session5 session6 meal_session3 meal_session4 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6) reps(5000) seed(123)
beep

*Meal Session 6
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese if child==1, cl(hh_id) method(xtreg) fe /// 
indepvar(meal_session6) controls(session3 session4 session5 session6 meal_session3 meal_session4 meal_session5 snack_session3 snack_session4 snack_session5 snack_session6) reps(5000) seed(123)
beep


*Snack Session 3
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese if child==1, cl(hh_id) method(xtreg) fe /// 
indepvar(snack_session3) controls(session3 session4 session5 session6 meal_session4 meal_session3 meal_session5 meal_session6  snack_session4 snack_session5 snack_session6) reps(5000) seed(123)
beep 

*Snack Session 4
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese if child==1, cl(hh_id) method(xtreg) fe /// 
indepvar(snack_session4) controls(session3 session4 session5 session6 meal_session4 meal_session3 meal_session5 meal_session6 snack_session3 snack_session5 snack_session6) reps(5000) seed(123)
beep 

*Snack Session 5
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese if child==1, cl(hh_id) method(xtreg) fe /// 
indepvar(snack_session5) controls(session3 session4 session5 session6 meal_session4 meal_session3 meal_session5 meal_session6 snack_session3 snack_session4 snack_session6) reps(5000) seed(123)
beep

*Snack Session 6
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese if child==1, cl(hh_id) method(xtreg) fe /// 
indepvar(snack_session6) controls(session3 session4 session5 session6 meal_session4 meal_session3 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5) reps(5000) seed(123)
beep


*Adults
*Romano Wolf - p-values
*Meal Session 3
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese if child==0, cl(hh_id) method(xtreg) fe /// 
indepvar(meal_session3) controls(session3 session4 session5 session6 meal_session4 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6) reps(5000) seed(123)
beep 

*Meal Session 4
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese if child==0, cl(hh_id) method(xtreg) fe /// 
indepvar(meal_session4) controls(session3 session4 session5 session6 meal_session3 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6) reps(5000) seed(123)
beep

*Meal Session 5
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese if child==0, cl(hh_id) method(xtreg) fe /// 
indepvar(meal_session5) controls(session3 session4 session5 session6 meal_session3 meal_session4 meal_session6 snack_session3 snack_session4 snack_session5 snack_session6) reps(5000) seed(123)
beep

*Meal Session 6
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese if child==0, cl(hh_id) method(xtreg) fe /// 
indepvar(meal_session6) controls(session3 session4 session5 session6 meal_session3 meal_session4 meal_session5 snack_session3 snack_session4 snack_session5 snack_session6) reps(5000) seed(123)
beep


*Snack Session 3
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese if child==0, cl(hh_id) method(xtreg) fe /// 
indepvar(snack_session3) controls(session3 session4 session5 session6 meal_session4 meal_session3 meal_session5 meal_session6  snack_session4 snack_session5 snack_session6) reps(5000) seed(123)
beep 

*Snack Session 4
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese fp_sweets if child==0, cl(hh_id) method(xtreg) fe /// 
indepvar(snack_session4) controls(session3 session4 session5 session6 meal_session4 meal_session3 meal_session5 meal_session6 snack_session3 snack_session5 snack_session6) reps(5000) seed(123)
beep 

*Snack Session 5
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese if child==0, cl(hh_id) method(xtreg) fe /// 
indepvar(snack_session5) controls(session3 session4 session5 session6 meal_session4 meal_session3 meal_session5 meal_session6 snack_session3 snack_session4 snack_session6) reps(5000) seed(123)
beep

*Snack Session 6
rwolf fp_fruit fp_veg fp_mfe fp_processed fp_sweets fp_bread fp_cheese if child==0, cl(hh_id) method(xtreg) fe /// 
indepvar(snack_session6) controls(session3 session4 session5 session6 meal_session4 meal_session3 meal_session5 meal_session6 snack_session3 snack_session4 snack_session5) reps(5000) seed(123)
beep







